local shunximengyv = fk.CreateSkill{
  name = "shunximengyv",
}

Fk:loadTranslationTable{
  ["shunximengyv"] = "梦域",
  [":shunximengyv"] = "回合结束时，你可以选择一名其他梦之队角色，令其获得一个额外的回合。",
  ["#shunximengyv"] = "选择一名角色，令其获得一个额外的回合。"
}


shunximengyv:addEffect(fk.EventPhaseStart, {
  anim_type = "support",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player, true),
    function(p) return  p.kingdom == "dream"
    end)
    return target == player and player.phase == Player.Discard and
      not player.dead and player:hasSkill(shunximengyv.name) and #targets > 0
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(player.room:getOtherPlayers(player, true),
    function(p) return  p.kingdom == "dream"
    end)
    local tos = room:askToChoosePlayers(player, {
      min_num = 1,
      max_num = 1,
      targets = targets,
      skill_name = shunximengyv.name,
      prompt = "#shunximengyv",
      cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    if not to.dead then
      to:gainAnExtraTurn(true, shunximengyv.name)
    end
  end,
})

return shunximengyv